﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraTab;
using DevExpress.XtraEditors;
using System.Windows.Forms;


namespace ThuVienTNN
{
    public static  class showTab
    {
        /// <summary>
        /// mo 1 tab cho dev
        /// </summary>
        /// <param name="tabControl"></param>
        /// <param name="frm"></param>
        public static void OpenTabPage (this XtraTabControl tabControl, XtraForm frm, FormWindowState windowState=FormWindowState.Maximized )
        {
            foreach (XtraTabPage  tab in tabControl.TabPages)
            {
                if (tab.Text == frm.Text)
                {
                    tabControl.SelectedTabPage = tab;
                    return;
                }
            }

            XtraTabPage tabPage = new XtraTabPage { Text = frm.Text };
            tabControl.TabPages.Add(tabPage);
            tabControl.SelectedTabPage = tabPage;
            frm.WindowState = windowState;
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.StartPosition = FormStartPosition.CenterParent;
            frm.TopLevel = false;
            frm.Parent = tabPage;
            frm.Show();
        }
        /// <summary>
        /// mo 1 tab cho win
        /// </summary>
        /// <param name="tabControl"></param>
        /// <param name="frm"></param>
        public static void OpenTabPage(this XtraTabControl tabControl, Form frm, FormWindowState windowState = FormWindowState.Maximized)
        {
            foreach (XtraTabPage tab in tabControl.TabPages)
            {
                if (tab.Text == frm.Text)
                {
                    tabControl.SelectedTabPage = tab;
                    return;
                }
            }

            XtraTabPage tabPage = new XtraTabPage { Text = frm.Text };
            tabControl.TabPages.Add(tabPage);
            tabControl.SelectedTabPage = tabPage;
            frm.WindowState = windowState;
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.TopLevel = false;
            frm.Parent = tabPage;
            frm.StartPosition = FormStartPosition.CenterParent;
            frm.Show();
        }
        /// <summary>
        /// dong tab hien tai
        /// </summary>
        /// <param name="parent"></param>
        public static void CloseCurrentTabPage(this Control parent)
        {
            if (parent == null) return;
            DevExpress.XtraTab.XtraTabPage tabPage = parent as DevExpress.XtraTab.XtraTabPage;
            DevExpress.XtraTab.XtraTabControl tabcontrol = tabPage.Parent as DevExpress.XtraTab.XtraTabControl;
            tabcontrol.TabPages.Remove(tabPage);
        }
    }


}
